package inits

import (
	"flag"
	"fmt"
	"log"
	"takeout-api/basic/config"
	__ "takeout-api/basic/proto"

	"google.golang.org/grpc"
	"google.golang.org/grpc/credentials/insecure"
)

func InitGrpc() {
	//初始化consul客户端
	consul := InitConsul("14.103.201.153:8500")

	conf := GrpcConf{
		Name:    "lyz-srv",
		Tags:    []string{"lyz-srv"},
		Port:    50051,
		Address: "127.0.0.1",
	}
	err := consul.RegisterService(conf)
	if err != nil {
		return
	}
	fmt.Println("consul 启动成功")
	flag.Parse()
	// Set up a connection to the server.
	conn, err := grpc.NewClient("127.0.0.1:50051", grpc.WithTransportCredentials(insecure.NewCredentials()))
	if err != nil {
		log.Fatalf("did not connect: %v", err)
	}
	config.TakeoutClient = __.NewTakeoutClient(conn)

}
